<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>UGH 单位换算工具</title>
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
            padding: 20px;
        }
        
        .container {
            max-width: 1000px;
            margin: 0 auto;
            background: white;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            padding: 30px;
        }
        
        header {
            text-align: center;
            margin-bottom: 30px;
            border-bottom: 1px solid #eee;
            padding-bottom: 20px;
        }
        
        h1 {
            color: #2c3e50;
            margin-bottom: 10px;
        }
        
        .description {
            color: #7f8c8d;
            font-size: 1.1rem;
        }
        
        .converter {
            display: flex;
            flex-direction: column;
            gap: 20px;
        }
        
        .category-selector {
            margin-bottom: 20px;
        }
        
        .category-selector label {
            display: block;
            margin-bottom: 10px;
            font-weight: bold;
            color: #2c3e50;
        }
        
        select {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
            background-color: #f9f9f9;
        }
        
        .conversion-area {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
        }
        
        .input-group {
            flex: 1;
            min-width: 300px;
        }
        
        .input-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #2c3e50;
        }
        
        .input-container {
            display: flex;
            border: 1px solid #ddd;
            border-radius: 5px;
            overflow: hidden;
        }
        
        .input-container input {
            flex: 1;
            padding: 12px;
            border: none;
            font-size: 16px;
        }
        
        .input-container select {
            width: auto;
            border: none;
            border-left: 1px solid #ddd;
            border-radius: 0;
        }
        
        .swap-button {
            align-self: center;
            background: #3498db;
            color: white;
            border: none;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            font-size: 18px;
            cursor: pointer;
            transition: background 0.3s;
        }
        
        .swap-button:hover {
            background: #2980b9;
        }
        
        .result {
            margin-top: 30px;
            padding: 20px;
            background: #e8f4fc;
            border-radius: 5px;
            text-align: center;
            font-size: 1.2rem;
            font-weight: bold;
            color: #2c3e50;
            display: none;
        }
        
        .unit-info {
            margin-top: 20px;
            padding: 15px;
            background: #f9f9f9;
            border-radius: 5px;
            font-size: 0.9rem;
            color: #7f8c8d;
        }
        
        footer {
            margin-top: 30px;
            text-align: center;
            color: #95a5a6;
            font-size: 0.9rem;
            border-top: 1px solid #eee;
            padding-top: 20px;
        }
        
        @media (max-width: 768px) {
            .conversion-area {
                flex-direction: column;
            }
            
            .swap-button {
                align-self: center;
                transform: rotate(90deg);
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>UGH 单位换算工具</h1>
            <p class="description">单位换算系统</p>
        </header>
        
        <div class="converter">
            <div class="category-selector">
                <label for="category">选择单位类别:</label>
                <select id="category">
                    <option value="">-- 请选择单位类别 --</option>
                    <!-- 单位类别将通过JavaScript动态填充 -->
                </select>
            </div>
            
            <div class="conversion-area">
                <div class="input-group">
                    <label for="fromValue">从:</label>
                    <div class="input-container">
                        <input type="number" id="fromValue" placeholder="输入数值">
                        <select id="fromUnit"></select>
                    </div>
                </div>
                
                <button class="swap-button" id="swapButton">⇄</button>
                
                <div class="input-group">
                    <label for="toValue">到:</label>
                    <div class="input-container">
                        <input type="number" id="toValue" placeholder="结果" readonly>
                        <select id="toUnit"></select>
                    </div>
                </div>
            </div>
            
            <div class="result" id="result"></div>
            
            <div class="unit-info" id="unitInfo">
                选择单位类别开始转换。转换公式: 目标单位 = (原始单位 × M) + B
            </div>
        </div>
        
        <footer>
            <p>无锡羽嘉慧科技有限公司</p>
        </footer>
    </div>

    <script>
        // 单位数据模型
        const unitData = {
            // 单位类别
            categories: {
                12: "Linear_Acceleration",
                28: "Angular_Acceleration",
                22: "Angular_Position",
                18: "Angular_Velocity",
                11: "Linear_Velocity",
                1: "Area",
                6: "Electrical_Potential",
                45: "Electrical_Potential_Rate",
                29: "Electrical_Resistance",
                5: "Electrical_Current",
                20: "dB",
                4: "Temperature",
                19: "Temperature_Delta",
                31: "Density",
                15: "Distance",
                21: "Flow",
                14: "Force",
                23: "Force_Rate",
                7: "Frequency",
                40: "Illuminance",
                16: "Inertia",
                42: "Loudness",
                41: "Luminous_Flux",
                3: "Percent",
                36: "Percent_Rate",
                25: "Power",
                27: "Power_Flux",
                8: "Pressure",
                9: "Pressure_Rate",
                32: "Spring_Rate",
                44: "Mixing_Ratio",
                30: "Strain",
                17: "Time",
                13: "Torque",
                35: "Torque_Rate",
                2: "Unitless",
                10: "Volume",
                26: "Energy",
                34: "Energy_Reactive",
                33: "Wear_Rate",
                38: "ACoeff",
                39: "BCoeff",
                43: "Electrical_Consumption"
            },
            
            // 单位定义
            units: [
			  { "type": 1, "m": 1, "b": 0, "cls": 20, "lng": "dB", "sht": "dB", "alt": "dBA dBB dBC" },
			  { "type": 7, "m": 1, "b": 0, "cls": 2, "lng": "stops", "sht": "stop", "alt": "" },
			  { "type": 145, "m": 1, "b": 0, "cls": 2, "lng": "µ", "sht": "µ", "alt": "Mu" },
			  { "type": 28, "m": 1, "b": 0, "cls": 2, "lng": "unitless", "sht": "unitless", "alt": "" },
			  { "type": 2, "m": 1, "b": 0, "cls": 2, "lng": "", "sht": "", "alt": "" },
			  { "type": 87, "m": 1, "b": 0, "cls": 3, "lng": "rh", "sht": "%rh", "alt": "" },
			  { "type": 3, "m": 1, "b": 0, "cls": 3, "lng": "%", "sht": "Percent", "alt": "" },
			  { "type": 4, "m": 1, "b": 0, "cls": 4, "lng": "°F", "sht": "F", "alt": "øF ?F" },
			  { "type": 5, "m": 0.5555555555555556, "b": -17.77777777777778, "cls": 4, "lng": "°C", "sht": "C", "alt": "øC ?C" },
			  { "type": 27, "m": 0.5555555555555556, "b": 255.22222222222223, "cls": 4, "lng": "°K", "sht": "K", "alt": "øK ?K" },
			  { "type": 120, "m": 1e+100, "b": 1e+100, "cls": 4, "lng": "!Temp", "sht": "!Temp", "alt": "" },
			  { "type": 6, "m": 1, "b": 0, "cls": 5, "lng": "amps", "sht": "amp", "alt": "" },
			  { "type": 159, "m": 1000, "b": 0, "cls": 5, "lng": "mA", "sht": "mAmp", "alt": "" },
			  { "type": 239, "m": 1000000, "b": 0, "cls": 5, "lng": "uA", "sht": "uAmp", "alt": "" },
			  { "type": 241, "m": 1000000000, "b": 0, "cls": 5, "lng": "pAmp", "sht": "pAmp", "alt": "" },
			  { "type": 242, "m": 1000000000000, "b": 0, "cls": 5, "lng": "fA", "sht": "fAmp", "alt": "" },
			  { "type": 8, "m": 1, "b": 0, "cls": 6, "lng": "volts", "sht": "volt", "alt": "" },
			  { "type": 75, "m": 1000, "b": 0, "cls": 6, "lng": "millvolts", "sht": "mv", "alt": "" },
			  { "type": 121, "m": 1e+100, "b": 1e+100, "cls": 6, "lng": "!Volt", "sht": "!Volt", "alt": "" },
			  { "type": 116, "m": 1, "b": 0, "cls": 7, "lng": "order", "sht": "order", "alt": "" },
			  { "type": 9, "m": 1, "b": 0, "cls": 7, "lng": "samps/sec", "sht": "sps", "alt": "" },
			  { "type": 16, "m": 1, "b": 0, "cls": 7, "lng": "Hz", "sht": "Hz", "alt": "" },
			  { "type": 98, "m": 0.0002777777777777778, "b": 0, "cls": 7, "lng": "cyc/hr", "sht": "cph", "alt": "" },
			  { "type": 249, "m": 0.001, "b": 0, "cls": 7, "lng": "kHz", "sht": "kHz", "alt": "" },
			  { "type": 122, "m": 1e+100, "b": 1e+100, "cls": 7, "lng": "!Freq", "sht": "!Freq", "alt": "" },
			  { "type": 10, "m": 1, "b": 0, "cls": 8, "lng": "psi", "sht": "psi", "alt": "" },
			  { "type": 11, "m": 0.0689475729, "b": 0, "cls": 8, "lng": "bar", "sht": "bar", "alt": "" },
			  { "type": 161, "m": 68.94757, "b": 0, "cls": 8, "lng": "millibar", "sht": "mbar", "alt": "" },
			  { "type": 12, "m": 6.894757, "b": 0, "cls": 8, "lng": "kPa", "sht": "kPa", "alt": "" },
			  { "type": 244, "m": 68.94757, "b": 0, "cls": 8, "lng": "HPa", "sht": "HPa", "alt": "" },
			  { "type": 13, "m": 0.0068939, "b": 0, "cls": 8, "lng": "MN/m²", "sht": "MN/m2", "alt": "MN/mý" },
			  { "type": 14, "m": 0.070295, "b": 0, "cls": 8, "lng": "kg/cm²", "sht": "kg/cm2", "alt": "kg/cmý" },
			  { "type": 15, "m": 0.006894757, "b": 0, "cls": 8, "lng": "Mpa", "sht": "Mpa", "alt": "" },
			  { "type": 77, "m": 2.0358, "b": 0, "cls": 8, "lng": "in·Hg", "sht": "in*Hg", "alt": "inùHg" },
			  { "type": 78, "m": 5.171, "b": 0, "cls": 8, "lng": "cm·Hg", "sht": "cm*Hg", "alt": "cmùHg" },
			  { "type": 84, "m": 27.681, "b": 0, "cls": 8, "lng": "in·wc", "sht": "in*wc", "alt": "inùwc" },
			  { "type": 203, "m": 703.0974, "b": 0, "cls": 8, "lng": "mm·wc", "sht": "mm*wc", "alt": "mmùwc" },
			  { "type": 97, "m": 51.71493257, "b": 0, "cls": 8, "lng": "mm·Hg", "sht": "mm*Hg", "alt": "mmùHg" },
			  { "type": 99, "m": 6894.757, "b": 0, "cls": 8, "lng": "Pa", "sht": "Pa", "alt": "" },
			  { "type": 171, "m": 0.689476, "b": 0, "cls": 8, "lng": "N/cm²", "sht": "N/cm2", "alt": "N/cmý" },
			  { "type": 198, "m": 51.71493257, "b": 759.9975, "cls": 8, "lng": "Torr", "sht": "Torr", "alt": "Torr" },
			  { "type": 205, "m": 0.068045779227, "b": 1, "cls": 8, "lng": "Atm", "sht": "Atm", "alt": "" },
			  { "type": 217, "m": 1, "b": 14.6959488, "cls": 8, "lng": "psiA", "sht": "psiA", "alt": "" },
			  { "type": 218, "m": 68.94757, "b": 1013.24656396, "cls": 8, "lng": "mbarA", "sht": "mbarA", "alt": "" },
			  { "type": 219, "m": 6894.757, "b": 101324.656396, "cls": 8, "lng": "PaA", "sht": "PaA", "alt": "" },
			  { "type": 220, "m": 6.894757, "b": 101.324656396, "cls": 8, "lng": "kPaA", "sht": "kPaA", "alt": "" },
			  { "type": 221, "m": 2.03602207, "b": 29.92122678, "cls": 8, "lng": "in·HgA", "sht": "in*HgA", "alt": "inùHgA" },
			  { "type": 222, "m": 51.71493257, "b": 759.9974777, "cls": 8, "lng": "mm·HgA", "sht": "mm*HgA", "alt": "mmùHgA" },
			  { "type": 223, "m": 5.171493257, "b": 75.99974777, "cls": 8, "lng": "cm·HgA", "sht": "cm*HgA", "alt": "cmùHgA" },
			  { "type": 119, "m": 1e+100, "b": 1e+100, "cls": 8, "lng": "!Press", "sht": "!Press", "alt": "" },
			  { "type": 17, "m": 1, "b": 0, "cls": 1, "lng": "in²", "sht": "sqin", "alt": "iný" },
			  { "type": 18, "m": 6.4516, "b": 0, "cls": 1, "lng": "cm²", "sht": "sqcm", "alt": "cmý" },
			  { "type": 19, "m": 0.00064516, "b": 0, "cls": 1, "lng": "m²", "sht": "sqm", "alt": "mý" },
			  { "type": 149, "m": 645.16, "b": 0, "cls": 1, "lng": "mm²", "sht": "sqmm", "alt": "mmý" },
			  { "type": 123, "m": 1e+100, "b": 1e+100, "cls": 1, "lng": "!Area", "sht": "!Area", "alt": "" },
			  { "type": 20, "m": 1, "b": 0, "cls": 9, "lng": "psi/sec", "sht": "psi/s", "alt": "" },
			  { "type": 21, "m": 0.068939, "b": 0, "cls": 9, "lng": "bar/sec", "sht": "bar/s", "alt": "" },
			  { "type": 22, "m": 6.894757, "b": 0, "cls": 9, "lng": "kPa/sec", "sht": "kPa/s", "alt": "" },
			  { "type": 23, "m": 0.070295, "b": 0, "cls": 9, "lng": "kg/cm²/s", "sht": "kg/cm2/s", "alt": "" },
			  { "type": 24, "m": 0.006894757, "b": 0, "cls": 9, "lng": "MPa/sec", "sht": "MPa/s", "alt": "" },
			  { "type": 172, "m": 0.689476, "b": 0, "cls": 9, "lng": "N/cm²/s", "sht": "N/cm2/s", "alt": "N/cmý/s" },
			  { "type": 124, "m": 1e+100, "b": 1e+100, "cls": 9, "lng": "!PrsRate", "sht": "!PrsRate", "alt": "" },
			  { "type": 25, "m": 1, "b": 0, "cls": 10, "lng": "in³", "sht": "ci", "alt": "cu-in" },
			  { "type": 26, "m": 16.387064, "b": 0, "cls": 10, "lng": "cm³", "sht": "cc", "alt": "ml" },
			  { "type": 82, "m": 16387.064, "b": 0, "cls": 10, "lng": "mm³", "sht": "cu-mm", "alt": "" },
			  { "type": 151, "m": 0.004329004329, "b": 0, "cls": 10, "lng": "gal", "sht": "gallon", "alt": "" },
			  { "type": 152, "m": 0.0005787037037, "b": 0, "cls": 10, "lng": "ft³", "sht": "cft", "alt": "" },
			  { "type": 153, "m": 1.6387064e-8, "b": 0, "cls": 10, "lng": "m³", "sht": "cu-m", "alt": "" },
			  { "type": 163, "m": 0.016387064, "b": 0, "cls": 10, "lng": "l", "sht": "liter", "alt": "" },
			  { "type": 125, "m": 1e+100, "b": 1e+100, "cls": 10, "lng": "!Volume", "sht": "!Volume", "alt": "" },
			  { "type": 30, "m": 1, "b": 0, "cls": 11, "lng": "mph", "sht": "mph", "alt": "mi/h mi/hr" },
			  { "type": 31, "m": 1.609344, "b": 0, "cls": 11, "lng": "kph", "sht": "kph", "alt": "km/h km/hr" },
			  { "type": 33, "m": 0.4470399, "b": 0, "cls": 11, "lng": "meter/s", "sht": "m/s", "alt": "" },
			  { "type": 34, "m": 1.4666667, "b": 0, "cls": 11, "lng": "feet/s", "sht": "ft/s", "alt": "" },
			  { "type": 94, "m": 17.6, "b": 0, "cls": 11, "lng": "in/s", "sht": "in/s", "alt": "" },
			  { "type": 95, "m": 447.0399, "b": 0, "cls": 11, "lng": "mm/s", "sht": "mm/s", "alt": "" },
			  { "type": 96, "m": 88, "b": 0, "cls": 11, "lng": "feet/m", "sht": "ft/m", "alt": "ft/min" },
			  { "type": 114, "m": 0.86897624, "b": 0, "cls": 11, "lng": "kts", "sht": "kts", "alt": "" },
			  { "type": 126, "m": 1e+100, "b": 1e+100, "cls": 11, "lng": "!LinSpd", "sht": "!LinSpd", "alt": "" },
			  { "type": 29, "m": 0.10471975511965977, "b": 0, "cls": 18, "lng": "rad/sec", "sht": "rad/sec", "alt": "" },
			  { "type": 32, "m": 1, "b": 0, "cls": 18, "lng": "rpm", "sht": "rpm", "alt": "rev/min" },
			  { "type": 86, "m": 6, "b": 0, "cls": 18, "lng": "°/s", "sht": "d/s", "alt": "dps deg/sec" },
			  { "type": 100, "m": 0.016666666666666666, "b": 0, "cls": 18, "lng": "rps", "sht": "rps", "alt": "" },
			  { "type": 127, "m": 1e+100, "b": 1e+100, "cls": 18, "lng": "!RotSpd", "sht": "!RotSpd", "alt": "" },
			  { "type": 35, "m": 1, "b": 0, "cls": 12, "lng": "ft/s²", "sht": "fpsps", "alt": "ft/sý" },
			  { "type": 36, "m": 0.3048, "b": 0, "cls": 12, "lng": "m/s²", "sht": "mpsps", "alt": "m/sý" },
			  { "type": 37, "m": 0.03108095017156793, "b": 0, "cls": 12, "lng": "g", "sht": "g", "alt": "" },
			  { "type": 142, "m": 0.6818181818181818, "b": 0, "cls": 12, "lng": "mph/s", "sht": "mph/s", "alt": "" },
			  { "type": 148, "m": 12, "b": 0, "cls": 12, "lng": "in/s²", "sht": "inpsps", "alt": "" },
			  { "type": 201, "m": 3.108095017156793, "b": 0, "cls": 12, "lng": "%g", "sht": "%g", "alt": "" },
			  { "type": 228, "m": 1.09728, "b": 0, "cls": 12, "lng": "kph/s", "sht": "kph/s", "alt": "" },
			  { "type": 128, "m": 1e+100, "b": 1e+100, "cls": 12, "lng": "!Accel", "sht": "!Accel", "alt": "" },
			  { "type": 42, "m": 12, "b": 0, "cls": 13, "lng": "lb·in", "sht": "lb*in", "alt": "lbùin" },
			  { "type": 43, "m": 0.012, "b": 0, "cls": 13, "lng": "klb·in", "sht": "klb*in", "alt": "klbùin" },
			  { "type": 40, "m": 1, "b": 0, "cls": 13, "lng": "lb·ft", "sht": "lb*ft", "alt": "lbùft" },
			  { "type": 44, "m": 0.001, "b": 0, "cls": 13, "lng": "Klb·ft", "sht": "klb*ft", "alt": "Klbùft" },
			  { "type": 38, "m": 13.8255, "b": 0, "cls": 13, "lng": "kg·cm", "sht": "kg*cm", "alt": "kgùcm" },
			  { "type": 39, "m": 0.138255, "b": 0, "cls": 13, "lng": "kg·m", "sht": "kg*m", "alt": "kgùm" },
			  { "type": 41, "m": 1.355816, "b": 0, "cls": 13, "lng": "N·m", "sht": "n*m", "alt": "Nùm nm" },
			  { "type": 79, "m": 0.1355816, "b": 0, "cls": 13, "lng": "m·daN", "sht": "m*daN", "alt": "mùdaN daNm" },
			  { "type": 162, "m": 0.001355816, "b": 0, "cls": 13, "lng": "kN·m", "sht": "kn*m", "alt": "kNùm" },
			  { "type": 129, "m": 1e+100, "b": 1e+100, "cls": 13, "lng": "!Torque", "sht": "!Torque", "alt": "" },
			  { "type": 147, "m": 1, "b": 0, "cls": 14, "lng": "lbf", "sht": "lbf", "alt": "" },
			  { "type": 45, "m": 1, "b": 0, "cls": 14, "lng": "lb", "sht": "lb", "alt": "" },
			  { "type": 46, "m": 4.448, "b": 0, "cls": 14, "lng": "N", "sht": "N", "alt": "" },
			  { "type": 47, "m": 0.4536, "b": 0, "cls": 14, "lng": "kg", "sht": "kg", "alt": "" },
			  { "type": 48, "m": 4.45e-6, "b": 0, "cls": 14, "lng": "MN", "sht": "MN", "alt": "" },
			  { "type": 81, "m": 0.4448, "b": 0, "cls": 14, "lng": "daN", "sht": "daN", "alt": "" },
			  { "type": 49, "m": 453.6, "b": 0, "cls": 14, "lng": "gr", "sht": "gram", "alt": "" },
			  { "type": 76, "m": 0.0005, "b": 0, "cls": 14, "lng": "tons", "sht": "ton", "alt": "" },
			  { "type": 93, "m": 0.004448, "b": 0, "cls": 14, "lng": "kN", "sht": "kN", "alt": "" },
			  { "type": 113, "m": 0.001, "b": 0, "cls": 14, "lng": "klb", "sht": "klb", "alt": "" },
			  { "type": 169, "m": 7000, "b": 0, "cls": 14, "lng": "grain", "sht": "grain", "alt": "" },
			  { "type": 202, "m": 16, "b": 0, "cls": 14, "lng": "oz", "sht": "ounce", "alt": "" },
			  { "type": 206, "m": 0.00045359999, "b": 0, "cls": 14, "lng": "Mton", "sht": "Mton", "alt": "" },
			  { "type": 224, "m": 453600, "b": 0, "cls": 14, "lng": "mg", "sht": "mgram", "alt": "" },
			  { "type": 225, "m": 453600000, "b": 0, "cls": 14, "lng": "ug", "sht": "ugram", "alt": "" },
			  { "type": 226, "m": 453600000000, "b": 0, "cls": 14, "lng": "ng", "sht": "ngram", "alt": "" },
			  { "type": 130, "m": 1e+100, "b": 1e+100, "cls": 14, "lng": "!Force", "sht": "!Force", "alt": "" },
			  { "type": 50, "m": 1, "b": 0, "cls": 15, "lng": "inch", "sht": "in", "alt": "" },
			  { "type": 56, "m": 0.08333333333333333, "b": 0, "cls": 15, "lng": "feet", "sht": "ft", "alt": "" },
			  { "type": 55, "m": 0.0254, "b": 0, "cls": 15, "lng": "meter", "sht": "m", "alt": "" },
			  { "type": 52, "m": 2.54, "b": 0, "cls": 15, "lng": "cm", "sht": "cm", "alt": "" },
			  { "type": 64, "m": 25400, "b": 0, "cls": 15, "lng": "micron", "sht": "um", "alt": "µm" },
			  { "type": 80, "m": 1000000, "b": 0, "cls": 15, "lng": "µinch", "sht": "uinch", "alt": "æinch" },
			  { "type": 83, "m": 1000, "b": 0, "cls": 15, "lng": "mil", "sht": "mils", "alt": "" },
			  { "type": 51, "m": 25.4, "b": 0, "cls": 15, "lng": "mm", "sht": "mm", "alt": "" },
			  { "type": 53, "m": 1.5782828282828283e-5, "b": 0, "cls": 15, "lng": "mile", "sht": "mi", "alt": "" },
			  { "type": 54, "m": 2.54e-5, "b": 0, "cls": 15, "lng": "km", "sht": "km", "alt": "" },
			  { "type": 227, "m": 25400000, "b": 0, "cls": 15, "lng": "nanometer", "sht": "nanometer", "alt": "" },
			  { "type": 131, "m": 1e+100, "b": 1e+100, "cls": 15, "lng": "!Dist", "sht": "!Dist", "alt": "" },
			  { "type": 58, "m": 1, "b": 0, "cls": 23, "lng": "lb/sec", "sht": "lb/s", "alt": "" },
			  { "type": 230, "m": 60, "b": 0, "cls": 23, "lng": "lb/min", "sht": "lb/min", "alt": "" },
			  { "type": 229, "m": 3600, "b": 0, "cls": 23, "lng": "lb/hr", "sht": "lb/hr", "alt": "" },
			  { "type": 57, "m": 4.448, "b": 0, "cls": 23, "lng": "N/sec", "sht": "N/s", "alt": "" },
			  { "type": 59, "m": 0.4536, "b": 0, "cls": 23, "lng": "Kg/sec", "sht": "kg/s", "alt": "" },
			  { "type": 85, "m": 0.4448, "b": 0, "cls": 23, "lng": "daN/sec", "sht": "daN/s", "alt": "" },
			  { "type": 170, "m": 0.004448, "b": 0, "cls": 23, "lng": "kN/sec", "sht": "kN/s", "alt": "" },
			  { "type": 197, "m": 444.8, "b": 0, "cls": 23, "lng": "gram/sec", "sht": "gram/s", "alt": "" },
			  { "type": 132, "m": 1e+100, "b": 1e+100, "cls": 23, "lng": "!FrcRate", "sht": "!FrcRate", "alt": "" },
			  { "type": 60, "m": 1, "b": 0, "cls": 16, "lng": "slug·ft²", "sht": "slug", "alt": "slugùftý" },
			  { "type": 61, "m": 1.355816, "b": 0, "cls": 16, "lng": "kg·m²", "sht": "kg*m2", "alt": "kgùmý" },
			  { "type": 62, "m": 0.13826, "b": 0, "cls": 16, "lng": "kg·m·s²", "sht": "kg*m*s2", "alt": "kgùmùsý" },
			  { "type": 146, "m": 32.158, "b": 0, "cls": 16, "lng": "lb·ft²", "sht": "lb*ft2", "alt": "" },
			  { "type": 160, "m": 1.3558, "b": 0, "cls": 16, "lng": "n·m·s²", "sht": "n*m*s2", "alt": "nùmùsý" },
			  { "type": 133, "m": 1e+100, "b": 1e+100, "cls": 16, "lng": "!Inertia", "sht": "!Inertia", "alt": "" },
			  { "type": 66, "m": 1000, "b": 0, "cls": 17, "lng": "ms", "sht": "msec", "alt": "" },
			  { "type": 65, "m": 1, "b": 0, "cls": 17, "lng": "sec", "sht": "second", "alt": "s" },
			  { "type": 67, "m": 0.016666666666666666, "b": 0, "cls": 17, "lng": "min", "sht": "minute", "alt": "" },
			  { "type": 68, "m": 0.0002777777777777778, "b": 0, "cls": 17, "lng": "hr", "sht": "hour", "alt": "" },
			  { "type": 63, "m": 1.1574074074074074e-5, "b": 0, "cls": 17, "lng": "day", "sht": "day", "alt": "" },
			  { "type": 199, "m": 1000000, "b": 0, "cls": 17, "lng": "us", "sht": "usec", "alt": "" },
			  { "type": 134, "m": 1e+100, "b": 1e+100, "cls": 17, "lng": "!Time", "sht": "!Time", "alt": "" },
			  { "type": 69, "m": 1, "b": 0, "cls": 19, "lng": "^°F", "sht": "^F", "alt": "^øF ^?F" },
			  { "type": 70, "m": 0.5555555555555556, "b": 0, "cls": 19, "lng": "^°C", "sht": "^C", "alt": "^øC ^?C" },
			  { "type": 135, "m": 1e+100, "b": 1e+100, "cls": 19, "lng": "!^Temp", "sht": "!^Temp", "alt": "" },
			  { "type": 71, "m": 1, "b": 0, "cls": 21, "lng": "gpm", "sht": "gpm", "alt": "" },
			  { "type": 72, "m": 3.785411784, "b": 0, "cls": 21, "lng": "lpm", "sht": "lpm", "alt": "" },
			  { "type": 155, "m": 3785.411784, "b": 0, "cls": 21, "lng": "cm³/min", "sht": "cc/min", "alt": "" },
			  { "type": 156, "m": 63.0902, "b": 0, "cls": 21, "lng": "cm³/sec", "sht": "cc/sec", "alt": "" },
			  { "type": 157, "m": 231, "b": 0, "cls": 21, "lng": "ci/min", "sht": "ci/min", "alt": "" },
			  { "type": 158, "m": 3.85, "b": 0, "cls": 21, "lng": "ci/sec", "sht": "ci/sec", "alt": "" },
			  { "type": 164, "m": 0.1336806, "b": 0, "cls": 21, "lng": "cfm", "sht": "cfm", "alt": "" },
			  { "type": 165, "m": 0.2271247, "b": 0, "cls": 21, "lng": "m³/hr", "sht": "m3/hr", "alt": "" },
			  { "type": 200, "m": 227.12470704, "b": 0, "cls": 21, "lng": "L/hr", "sht": "L/hr", "alt": "" },
			  { "type": 136, "m": 1e+100, "b": 1e+100, "cls": 21, "lng": "!Flow", "sht": "!Flow", "alt": "" },
			  { "type": 73, "m": 1, "b": 0, "cls": 22, "lng": "°", "sht": "degrees", "alt": "ø ? deg" },
			  { "type": 74, "m": 0.017453292519943295, "b": 0, "cls": 22, "lng": "radians", "sht": "rad", "alt": "" },
			  { "type": 88, "m": 0.002777777777777778, "b": 0, "cls": 22, "lng": "revs", "sht": "revs", "alt": "" },
			  { "type": 89, "m": 2.7777777777777776e-6, "b": 0, "cls": 22, "lng": "krevs", "sht": "krevs", "alt": "" },
			  { "type": 137, "m": 1e+100, "b": 1e+100, "cls": 22, "lng": "!AngPos", "sht": "!AngPos", "alt": "" },
			  { "type": 90, "m": 1000, "b": 0, "cls": 25, "lng": "Watt", "sht": "watt", "alt": "" },
			  { "type": 91, "m": 1, "b": 0, "cls": 25, "lng": "kWatt", "sht": "kW", "alt": "" },
			  { "type": 92, "m": 1.341022038, "b": 0, "cls": 25, "lng": "hp", "sht": "hp", "alt": "" },
			  { "type": 183, "m": 3412, "b": 0, "cls": 25, "lng": "Btu", "sht": "Btu", "alt": "" },
			  { "type": 250, "m": 1000, "b": 0, "cls": 25, "lng": "J/s", "sht": "J/s", "alt": "" },
			  { "type": 251, "m": 44253.73, "b": 0, "cls": 25, "lng": "ft·lb/min", "sht": "ft*lb/min", "alt": "" },
			  { "type": 252, "m": 737.56, "b": 0, "cls": 25, "lng": "ft·lb/sec", "sht": "ft*lb/sec", "alt": "" },
			  { "type": 253, "m": 60000, "b": 0, "cls": 25, "lng": "n·m/min", "sht": "n*m/min", "alt": "" },
			  { "type": 254, "m": 1000, "b": 0, "cls": 25, "lng": "n·m/sec", "sht": "n*m/sec", "alt": "" },
			  { "type": 138, "m": 1e+100, "b": 1e+100, "cls": 25, "lng": "!Power", "sht": "!Power", "alt": "" },
			  { "type": 109, "m": 1, "b": 0, "cls": 27, "lng": "W/cm²", "sht": "W/cm2", "alt": "W/cm^2" },
			  { "type": 110, "m": 0.001, "b": 0, "cls": 27, "lng": "kW/cm²", "sht": "kW/cm2", "alt": "kW/cm^2" },
			  { "type": 111, "m": 0.0086517366233, "b": 0, "cls": 27, "lng": "hp/in²", "sht": "hp/in2", "alt": "hp/in^2" },
			  { "type": 238, "m": 10000, "b": 0, "cls": 27, "lng": "W/m²", "sht": "W/m2", "alt": "W/m^2" },
			  { "type": 139, "m": 1e+100, "b": 1e+100, "cls": 27, "lng": "!PwrFlux", "sht": "!PwrFlux", "alt": "" },
			  { "type": 101, "m": 3600000, "b": 0, "cls": 26, "lng": "joule", "sht": "joule", "alt": "" },
			  { "type": 102, "m": 3600, "b": 0, "cls": 26, "lng": "kilo-joule", "sht": "kJ", "alt": "" },
			  { "type": 103, "m": 1, "b": 0, "cls": 26, "lng": "kWh", "sht": "kWh", "alt": "" },
			  { "type": 243, "m": 1000, "b": 0, "cls": 26, "lng": "Wh", "sht": "Wh", "alt": "" },
			  { "type": 104, "m": 860000, "b": 0, "cls": 26, "lng": "calorie", "sht": "cal", "alt": "" },
			  { "type": 105, "m": 860, "b": 0, "cls": 26, "lng": "KCalorie", "sht": "kcal", "alt": "" },
			  { "type": 106, "m": 1.341022038, "b": 0, "cls": 26, "lng": "hp-hr", "sht": "hp-hr", "alt": "" },
			  { "type": 107, "m": 3412.698413, "b": 0, "cls": 26, "lng": "Btu-hr", "sht": "Btu-hr", "alt": "" },
			  { "type": 108, "m": 2655300, "b": 0, "cls": 26, "lng": "ft-lb", "sht": "ft-lb", "alt": "" },
			  { "type": 112, "m": 3.6, "b": 0, "cls": 26, "lng": "MJoule", "sht": "MJ", "alt": "" },
			  { "type": 115, "m": 2.6553, "b": 0, "cls": 26, "lng": "Mft-lb", "sht": "Mft-lb", "alt": "" },
			  { "type": 140, "m": 1e+100, "b": 1e+100, "cls": 26, "lng": "!Energy", "sht": "!Energy", "alt": "" },
			  { "type": 184, "m": 1, "b": 0, "cls": 34, "lng": "kVARh", "sht": "kVARh", "alt": "" },
			  { "type": 185, "m": 1000, "b": 0, "cls": 34, "lng": "VARh", "sht": "VARh", "alt": "" },
			  { "type": 186, "m": 1e+100, "b": 1e+100, "cls": 34, "lng": "!RctEng", "sht": "!RctEng", "alt": "" },
			  { "type": 117, "m": 1, "b": 0, "cls": 28, "lng": "deg/s²", "sht": "degpsps", "alt": "" },
			  { "type": 118, "m": 0.017453292519943295, "b": 0, "cls": 28, "lng": "rad/s²", "sht": "radpsps", "alt": "" },
			  { "type": 144, "m": 0.002777777777777778, "b": 0, "cls": 28, "lng": "rev/s²", "sht": "revpsps", "alt": "" },
			  { "type": 143, "m": 0.16666666666666666, "b": 0, "cls": 28, "lng": "rpm/s", "sht": "rpm/s", "alt": "" },
			  { "type": 141, "m": 1e+100, "b": 1e+100, "cls": 28, "lng": "!AngAcl", "sht": "!AngAcl", "alt": "" },
			  { "type": 154, "m": 1, "b": 0, "cls": 29, "lng": "Ohm", "sht": "Ohms", "alt": "" },
			  { "type": 166, "m": 1, "b": 0, "cls": 30, "lng": "µStrn", "sht": "µStrn", "alt": "" },
			  { "type": 167, "m": 1000000, "b": 0, "cls": 30, "lng": "Strn", "sht": "Strn", "alt": "" },
			  { "type": 168, "m": 1e+100, "b": 1e+100, "cls": 30, "lng": "!Strain", "sht": "!Strain", "alt": "" },
			  { "type": 173, "m": 1, "b": 0, "cls": 31, "lng": "kg/m³", "sht": "kg/m3", "alt": "" },
			  { "type": 174, "m": 0.062428, "b": 0, "cls": 31, "lng": "lb/ft³", "sht": "lb/ft", "alt": "" },
			  { "type": 235, "m": 1000000000, "b": 0, "cls": 31, "lng": "ug/m³", "sht": "ug/m3", "alt": "" },
			  { "type": 236, "m": 1000, "b": 0, "cls": 31, "lng": "g/m³", "sht": "g/m3", "alt": "" },
			  { "type": 240, "m": 1000000, "b": 0, "cls": 31, "lng": "mg/m³", "sht": "mg/m3", "alt": "" },
			  { "type": 179, "m": 1e+100, "b": 1e+100, "cls": 31, "lng": "!Density", "sht": "!Density", "alt": "" },
			  { "type": 175, "m": 1, "b": 0, "cls": 32, "lng": "lb/in", "sht": "lb/in", "alt": "" },
			  { "type": 176, "m": 175.11811023622047, "b": 0, "cls": 32, "lng": "N/m", "sht": "N/m", "alt": "" },
			  { "type": 177, "m": 0.17511811023622047, "b": 0, "cls": 32, "lng": "N/mm", "sht": "N/mm", "alt": "" },
			  { "type": 178, "m": 1e+100, "b": 1e+100, "cls": 32, "lng": "!SpringRate", "sht": "!SpringRate", "alt": "" },
			  { "type": 180, "m": 1, "b": 0, "cls": 33, "lng": "in/kWh", "sht": "in/kWh", "alt": "" },
			  { "type": 181, "m": 25.4, "b": 0, "cls": 33, "lng": "mm/kWh", "sht": "mm/kWh", "alt": "" },
			  { "type": 182, "m": 1e+100, "b": 1e+100, "cls": 33, "lng": "!WearRate", "sht": "!WearRate", "alt": "" },
			  { "type": 187, "m": 12, "b": 0, "cls": 35, "lng": "lb·in/s", "sht": "lb*in/s", "alt": "" },
			  { "type": 188, "m": 0.012, "b": 0, "cls": 35, "lng": "klb·in/s", "sht": "klb*in/s", "alt": "" },
			  { "type": 189, "m": 1, "b": 0, "cls": 35, "lng": "lb·ft/s", "sht": "lb*ft/s", "alt": "" },
			  { "type": 190, "m": 0.001, "b": 0, "cls": 35, "lng": "Klb·ft/s", "sht": "klb*ft/s", "alt": "" },
			  { "type": 191, "m": 13.8255, "b": 0, "cls": 35, "lng": "kg·cm/s", "sht": "kg*cm/s", "alt": "" },
			  { "type": 192, "m": 0.138255, "b": 0, "cls": 35, "lng": "kg·m/s", "sht": "kg*m/s", "alt": "" },
			  { "type": 193, "m": 1.355816, "b": 0, "cls": 35, "lng": "N·m/s", "sht": "n*m/s", "alt": "" },
			  { "type": 194, "m": 0.1355816, "b": 0, "cls": 35, "lng": "m·daN/s", "sht": "m*daN/s", "alt": "" },
			  { "type": 195, "m": 0.001355816, "b": 0, "cls": 35, "lng": "kN·m.s", "sht": "kn*m/s", "alt": "" },
			  { "type": 196, "m": 1e+100, "b": 1e+100, "cls": 35, "lng": "!TrqRate", "sht": "!TrqRate", "alt": "" },
			  { "type": 204, "m": 1, "b": 0, "cls": 36, "lng": "%/s", "sht": "percent/sec", "alt": "" },
			  { "type": 210, "m": 1, "b": 0, "cls": 38, "lng": "N/kph²", "sht": "N/kph²", "alt": "" },
			  { "type": 211, "m": 0.5824, "b": 0, "cls": 38, "lng": "lb/mph²", "sht": "lb/mph²", "alt": "" },
			  { "type": 215, "m": 1, "b": 0, "cls": 39, "lng": "N/kph", "sht": "N/kph", "alt": "" },
			  { "type": 216, "m": 0.3618, "b": 0, "cls": 39, "lng": "lb/mph", "sht": "lb/mph", "alt": "" },
			  { "type": 231, "m": 1, "b": 0, "cls": 40, "lng": "lux", "sht": "lux", "alt": "" },
			  { "type": 232, "m": 0.002, "b": 0, "cls": 40, "lng": "µmoles/s/m²", "sht": "umoles/s/m2", "alt": "" },
			  { "type": 233, "m": 1, "b": 0, "cls": 41, "lng": "lumens", "sht": "lumens", "alt": "" },
			  { "type": 234, "m": 1, "b": 0, "cls": 41, "lng": "lumen", "sht": "lumen", "alt": "" },
			  { "type": 237, "m": 1, "b": 0, "cls": 42, "lng": "sone", "sht": "sones", "alt": "" },
			  { "type": 245, "m": 1, "b": 0, "cls": 43, "lng": "Wh/km", "sht": "Wh/km", "alt": "" },
			  { "type": 246, "m": 0.001, "b": 0, "cls": 43, "lng": "KWh/km", "sht": "KWh/km", "alt": "" },
			  { "type": 247, "m": 1.609344, "b": 0, "cls": 43, "lng": "Wh/mi", "sht": "Wh/mi", "alt": "" },
			  { "type": 248, "m": 0.001609344, "b": 0, "cls": 43, "lng": "KWh/mi", "sht": "KWh/mi", "alt": "" },
			  { "type": 255, "m": 1, "b": 0, "cls": 44, "lng": "Grain/lb", "sht": "Grain/lb", "alt": "" },
			  { "type": 256, "m": 0.1428571429, "b": 0, "cls": 44, "lng": "g/kg", "sht": "g/kg", "alt": "" },
			  { "type": 257, "m": 1, "b": 0, "cls": 45, "lng": "volts/s", "sht": "volt/s", "alt": "" },
			  { "type": 258, "m": 1000, "b": 0, "cls": 45, "lng": "millivolts/s", "sht": "millivolt/s", "alt": "" }
			]
        };

        // DOM 元素
        const categorySelect = document.getElementById('category');
        const fromUnitSelect = document.getElementById('fromUnit');
        const toUnitSelect = document.getElementById('toUnit');
        const fromValueInput = document.getElementById('fromValue');
        const toValueInput = document.getElementById('toValue');
        const swapButton = document.getElementById('swapButton');
        const resultDiv = document.getElementById('result');
        const unitInfoDiv = document.getElementById('unitInfo');

        // 初始化页面
        function init() {
            // 填充类别选择器
            for (const [id, name] of Object.entries(unitData.categories)) {
                const option = document.createElement('option');
                option.value = id;
                option.textContent = name;
                categorySelect.appendChild(option);
            }
            
            // 添加事件监听器
            categorySelect.addEventListener('change', onCategoryChange);
            fromValueInput.addEventListener('input', convert);
            fromUnitSelect.addEventListener('change', convert);
            toUnitSelect.addEventListener('change', convert);
            swapButton.addEventListener('click', swapUnits);
        }

        // 当类别改变时更新单位选择器
        function onCategoryChange() {
            const categoryId = parseInt(categorySelect.value);
            
            // 清空单位选择器
            fromUnitSelect.innerHTML = '';
            toUnitSelect.innerHTML = '';
            
            // 如果没有选择类别，则返回
            if (!categoryId) {
                resultDiv.style.display = 'none';
                unitInfoDiv.textContent = '选择单位类别开始转换。转换公式: 目标单位 = (原始单位 × M) + B';
                return;
            }
            
            // 获取该类别的所有单位
            const categoryUnits = unitData.units.filter(unit => unit.cls === categoryId);
            
            // 填充单位选择器
            categoryUnits.forEach(unit => {
                const fromOption = document.createElement('option');
                fromOption.value = unit.type;
                fromOption.textContent = unit.lng || unit.sht;
                fromUnitSelect.appendChild(fromOption);
                
                const toOption = document.createElement('option');
                toOption.value = unit.type;
                toOption.textContent = unit.lng || unit.sht;
                toUnitSelect.appendChild(toOption);
            });
            
            // 设置默认选择（如果有单位）
            if (categoryUnits.length > 0) {
                fromUnitSelect.selectedIndex = 0;
                toUnitSelect.selectedIndex = Math.min(1, categoryUnits.length - 1);
                
                // 更新单位信息
                updateUnitInfo();
                
                // 执行转换
                convert();
            }
        }

        // 更新单位信息显示
        function updateUnitInfo() {
            const fromUnitType = parseInt(fromUnitSelect.value);
            const toUnitType = parseInt(toUnitSelect.value);
            
            const fromUnit = unitData.units.find(u => u.type === fromUnitType);
            const toUnit = unitData.units.find(u => u.type === toUnitType);
            
            if (fromUnit && toUnit) {
                let info = `转换公式: 目标单位 = (原始单位 × ${toUnit.m}) + ${toUnit.b}`;
                
                if (fromUnit.alt) {
                    info += ` | 替代名称: ${fromUnit.alt}`;
                }
                
                unitInfoDiv.textContent = info;
            }
        }

        // 执行单位转换
        function convert() {
            const fromValue = parseFloat(fromValueInput.value);
            const fromUnitType = parseInt(fromUnitSelect.value);
            const toUnitType = parseInt(toUnitSelect.value);
            
            // 验证输入
            if (isNaN(fromValue) || !fromUnitType || !toUnitType) {
                toValueInput.value = '';
                resultDiv.style.display = 'none';
                return;
            }
            
            // 获取单位定义
            const fromUnit = unitData.units.find(u => u.type === fromUnitType);
            const toUnit = unitData.units.find(u => u.type === toUnitType);
            
            if (!fromUnit || !toUnit) {
                toValueInput.value = '';
                resultDiv.style.display = 'none';
                return;
            }
            
            // 执行转换: 目标单位 = (原始单位 × M_to/M_from) + (B_to - B_from × M_to/M_from)
            // 首先转换为基本单位，然后再转换为目标单位
            const valueInBase = (fromValue - fromUnit.b) / fromUnit.m;
            const result = valueInBase * toUnit.m + toUnit.b;
            
            // 显示结果
            toValueInput.value = result.toFixed(6);
            
            // 显示转换结果文本
            const fromUnitText = fromUnit.lng || fromUnit.sht;
            const toUnitText = toUnit.lng || toUnit.sht;
            resultDiv.innerHTML = `${fromValue} ${fromUnitText} = ${result.toFixed(6)} ${toUnitText}`;
            resultDiv.style.display = 'block';
            
            // 更新单位信息
            updateUnitInfo();
        }

        // 交换单位
        function swapUnits() {
            const fromUnitIndex = fromUnitSelect.selectedIndex;
            const toUnitIndex = toUnitSelect.selectedIndex;
            
            fromUnitSelect.selectedIndex = toUnitIndex;
            toUnitSelect.selectedIndex = fromUnitIndex;
            
            const fromValue = fromValueInput.value;
            fromValueInput.value = toValueInput.value;
            toValueInput.value = fromValue;
            
            convert();
        }

        // 初始化应用
        document.addEventListener('DOMContentLoaded', init);
    </script>
</body>
</html>